package com.southwind.controller;


import com.southwind.entity.OrderMaster;
import com.southwind.service.IOrderMasterService;
import com.southwind.vo.OrderMasterPageVO;
import com.southwind.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 前端控制器 卖家端
 * </p>
 *
 * @author admin
 * @since 2021-04-18
 */
@RestController
@RequestMapping("/seller/order")
public class OrderMasterSellerController {

    @Autowired
    private IOrderMasterService orderMasterService;

    /**
     * 订单列表
     */
    @GetMapping("/list/{page}/{size}")
    public ResultVO<OrderMasterPageVO> list(@PathVariable Long page, @PathVariable Long size) {
        OrderMasterPageVO orderMasterPageVO = orderMasterService.orderMasterVO(page, size);
        return ResultVO.successWithData(orderMasterPageVO);
    }

    /**
     * 取消订单
     */
    @PutMapping("/cancel/{orderId}")
    public ResultVO cancel(@PathVariable String orderId) {
        OrderMaster orderMaster = new OrderMaster();
        orderMaster.setOrderId(orderId);
        orderMaster.setOrderStatus(2);
        boolean b = orderMasterService.updateById(orderMaster);
        return ResultVO.auto(b);
    }

    /**
     * 完结订单
     */
    @PutMapping("/finish/{orderId}")
    public ResultVO finish(@PathVariable String orderId) {
        OrderMaster orderMaster = new OrderMaster();
        orderMaster.setOrderId(orderId);
        orderMaster.setOrderStatus(1);
        boolean b = orderMasterService.updateById(orderMaster);
        return ResultVO.auto(b);
    }

}

